package net.neiquanlib.base;

import android.view.View;

import net.neiquanlib.R;
import net.neiquanlib.widget.RefreshLayout;
import net.neiquanlib.xlistview.XListView;

/**
 * Created by hjb on 2015/12/31.
 */
public abstract class BaseListViewFragment extends AppBaseFragment implements XListView.IXListViewListener, RefreshLayout.RetryListener {

    public int pageNum = 0;
    public final int PAEG_SIZE = 10;
    public RefreshLayout mRefresh;
    public XListView mXListView;
    public MyBaseAdapterListView adapter;
    private View mHeadView;

    @Override
    public View initRootView() {
        rootView = mInflater.inflate(R.layout.base_xlistview_fragment, null);
        return rootView;
    }

    private void findViews() {
        mHeadView = rootView.findViewById(R.id.head_view);
        mRefresh = (RefreshLayout) rootView.findViewById(R.id.refresh);
        mXListView = (XListView) rootView.findViewById(R.id.xListView);
    }

    @Override
    public void setViews() {
        findViews();
        mRefresh.setRetryListener(this);
        mXListView.setXListViewListener(this);
        mXListView.setPullRefreshEnable(true);
        mXListView.setPullLoadEnable(false);
        adapter = getAdapter();
        mXListView.setAdapter(adapter);
        setHeadView(isHaveHead());
        setHeadViews();
    }

    @Override
    public void onResume() {
        super.onResume();
//        mXListView.autoRefresh();//onResume时候自动刷新
    }

    private void setHeadView(boolean isHaveHead) {
        if (!isHaveHead) {
            mHeadView.setVisibility(View.GONE);
        }
    }
    protected abstract boolean isHaveHead();
    protected abstract MyBaseAdapterListView getAdapter();
    /**
     * 当返回为true时候设置
     */
    protected abstract void setHeadViews();
}
